home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / mordor_2.000 / mordor_2 / src / command10.c < prev    next >
C/C++ Source or Header  |  1995-04-09  |  29KB  |  949 lines

  1. /*
  2.  * COMMAND10.C:
  3.  *
  4.  *  Additional user routines.
  5.  *
  6.  *
  7.  */
  8.  
  9. #include "mstruct.h"
  10. #include "mextern.h"
  11.  
  12. /**********************************************************************/
  13. /*                           sneak                                   */
  14. /**********************************************************************/
  15.  
  16.  
  17. int sneak(ply_ptr, cmnd)
  18. creature    *ply_ptr;
  19. cmd     *cmnd;
  20. {
  21.     room        *rom_ptr, *old_rom_ptr;
  22.     creature    *crt_ptr;
  23.     ctag        *cp, *temp;
  24.     exit_       *ext_ptr;
  25.     long        i, t;
  26.     int     fd, old_rom_num, fall, dmg, n;
  27.     int         chance;
  28.  
  29.     rom_ptr = ply_ptr->parent_rom;
  30.     fd = ply_ptr->fd;
  31.  
  32.     if(ply_ptr->class != ASSASSIN && ply_ptr->class != THIEF && ply_ptr->class < CARETAKER) {
  33.                 print(fd, "Only thieves & assassins may sneak.\n");
  34.                 return(0);
  35.         }                  
  36.  
  37.     if(!F_ISSET(ply_ptr, PHIDDN)){
  38.                 print(fd, "You need to hide first.\n");
  39.                 return(0);
  40.         }                  
  41.  
  42.     if(cmnd->num < 2) {
  43.         print(fd, "Sneak where?\n");
  44.         return(0);
  45.     }
  46.  
  47.     ext_ptr = find_ext(ply_ptr, rom_ptr->first_ext, 
  48.                cmnd->str[1], cmnd->val[1]);
  49.  
  50.     if(!ext_ptr) {
  51.         print(fd, "I don't see that exit.\n");
  52.         return(0);
  53.     }
  54.  
  55.     if(F_ISSET(ext_ptr, XLOCKD)) {
  56.         print(fd, "It's locked.\n");
  57.         return(0);
  58.     }
  59.     else if(F_ISSET(ext_ptr, XCLOSD)) {
  60.         print(fd, "You have to open it first.\n");
  61.         return(0);
  62.     }
  63.  
  64.     if(F_ISSET(ext_ptr, XFLYSP) && !F_ISSET(ply_ptr, PFLYSP)) {
  65.         print(fd, "You must fly to get there.\n");
  66.         return(0);
  67.     }
  68.  
  69.     if(F_ISSET(ext_ptr, XNAKED) && weight_ply(ply_ptr)) {
  70.         print(fd, "You cannot bring anything through that exit.\n");
  71.         return(0);
  72.     }
  73.  
  74.  
  75.     if(F_ISSET(ext_ptr, XPLDGK)) 
  76.      if (!F_ISSET(ply_ptr, PPLDGK)){
  77.             print(fd, "You do not have the proper authorization to go there.\n");
  78.             return(0);
  79.      }
  80.      else if (BOOL(F_ISSET(ext_ptr,XKNGDM)) !=  BOOL(F_ISSET(ply_ptr, PKNGDM))){
  81.             print(fd, "You belong to the wrong organization to go there.\n");
  82.             return(0);
  83.          }          
  84.  
  85.     t = Time%24L;
  86.     if(F_ISSET(ext_ptr, XNGHTO) && (t>6 && t < 20)) {
  87.         print(fd, "That exit is not open during the day.\n");
  88.         return(0);
  89.     }          
  90.  
  91.     if(F_ISSET(ext_ptr, XDAYON) && (t<6 || t > 20)) {
  92.         print(fd, "That exit is closed for the night.\n");
  93.         return(0);
  94.     }          
  95.  
  96.     if(F_ISSET(ext_ptr,XPGUAR)){
  97.         cp = rom_ptr->first_mon;
  98.         while(cp) {
  99.             if(F_ISSET(cp->crt, MPGUAR)) { 
  100.                 if(!F_ISSET(ply_ptr, PINVIS) && ply_ptr->class < CARETAKER){
  101.                 print(fd, "%M blocks your exit.\n", cp->crt);
  102.                 return(0);
  103.         }
  104.              if(F_ISSET(cp->crt, MDINVI) && ply_ptr->class < CARETAKER) {
  105.                print(fd, "%M blocks your exit.\n", cp->crt);
  106.                 return(0);
  107.         }
  108.             }
  109.             cp = cp->next_tag;
  110.         }
  111.     }         
  112.  
  113.     if(F_ISSET(ext_ptr, XFEMAL) && F_ISSET(ply_ptr, PMALES)){
  114.         print(fd, "Sorry, only females are allowed to go there.\n");
  115.         return(0); 
  116.     }
  117.     if(F_ISSET(ext_ptr, XMALES) && !F_ISSET(ply_ptr, PMALES)){
  118.         print(fd, "Sorry, only males are allowed to go there.\n");
  119.         return(0); 
  120.     }           
  121.  
  122.     if((F_ISSET(ext_ptr, XCLIMB) || F_ISSET(ext_ptr, XREPEL)) &&
  123.        !F_ISSET(ply_ptr, PLEVIT)) {
  124.         fall = (F_ISSET(ext_ptr, XDCLIM) ? 50:0) + 50 - 
  125.                fall_ply(ply_ptr);
  126.  
  127.         if(mrand(1,100) < fall) {
  128.             dmg = mrand(5, 15+fall/10);
  129.             if(ply_ptr->hpcur <= dmg){
  130.                    print(fd, "You fell to your death.\n");
  131.                    ply_ptr->hpcur=0;
  132.                    broadcast_rom(fd, ply_ptr->rom_num, "%M died from the fall.\n");
  133.                    die(ply_ptr, ply_ptr);
  134.                    return(0);
  135.             }
  136.  
  137.             ply_ptr->hpcur -= dmg;
  138.             print(fd, "You fell and hurt yourself for %d damage.\n",
  139.                   dmg);
  140.             broadcast_rom(fd, ply_ptr->rom_num, "%M fell down.", 
  141.                       ply_ptr);
  142.  
  143.         if(ply_ptr->hpcur < 1) {
  144.                                 print(fd, "You died.\n");
  145.                                 die(ply_ptr, ply_ptr);
  146.         }
  147.  
  148.             if(F_ISSET(ext_ptr, XCLIMB))
  149.                 return(0);
  150.         }
  151.     }
  152.  
  153.     i = LT(ply_ptr, LT_ATTCK);
  154.     t = time(0);
  155.     if(t < i) {
  156.         please_wait(fd, i-t);
  157.         return(0);
  158.     }
  159.         chance = MIN(85, 5 + 6*ply_ptr->level + 
  160.                 3*bonus[ply_ptr->dexterity]);    
  161.     if(F_ISSET(ply_ptr, PBLIND))
  162.         chance = MIN(20, chance);
  163.  
  164.     if(mrand(1,100) > chance) 
  165.     {
  166.         print(fd,"You failed to sneak.\n"); 
  167.         F_CLR(ply_ptr, PHIDDN);
  168.  
  169.         cp = rom_ptr->first_mon;
  170.         while(cp) {
  171.             if(F_ISSET(cp->crt, MBLOCK) && 
  172.             is_enm_crt(ply_ptr->name, cp->crt) &&
  173.             !F_ISSET(ply_ptr, PINVIS) && ply_ptr->class < CARETAKER) {
  174.                 print(fd, "%M blocks your exit.\n", cp->crt);
  175.                 return(0);
  176.             }
  177.             cp = cp->next_tag;
  178.         }
  179.     }
  180.  
  181.     if(!F_ISSET(rom_ptr, RPTRAK))
  182.         strcpy(rom_ptr->track, ext_ptr->name);
  183.  
  184.     old_rom_num = rom_ptr->rom_num;
  185.     old_rom_ptr = rom_ptr;
  186.  
  187.     load_rom(ext_ptr->room, &rom_ptr);
  188.     if(rom_ptr == old_rom_ptr) {
  189.         print(fd, "Off map in that direction.\n");
  190.         return(0);
  191.     }
  192.  
  193.     n = count_vis_ply(rom_ptr);
  194.  
  195.     if(rom_ptr->lolevel > ply_ptr->level && ply_ptr->class < CARETAKER) {
  196.         print(fd, "You must be at least level %d to go that way.\n",
  197.               rom_ptr->lolevel);
  198.         return(0);
  199.     }
  200.     else if(ply_ptr->level > rom_ptr->hilevel && rom_ptr->hilevel &&
  201.         ply_ptr->class < CARETAKER) {
  202.         print(fd, "Only players under level %d may go that way.\n",
  203.               rom_ptr->hilevel+1);
  204.         return(0);
  205.     }
  206.     else if((F_ISSET(rom_ptr, RONEPL) && n > 0) ||
  207.         (F_ISSET(rom_ptr, RTWOPL) && n > 1) ||
  208.         (F_ISSET(rom_ptr, RTHREE) && n > 2)) {
  209.         print(fd, "That room is full.\n");
  210.         return(0);
  211.     }
  212.  
  213.     if(!F_ISSET(ply_ptr, PHIDDN))
  214.         if(strcmp(ext_ptr->name, "up") && strcmp(ext_ptr->name, "down") 
  215.            && strcmp(ext_ptr->name, "out") && !F_ISSET(ply_ptr, PDMINV)) {
  216.                 broadcast_rom(fd, old_rom_ptr->rom_num, "%M went to the %s.", 
  217.                               ply_ptr, ext_ptr->name);
  218.         }
  219.         else if(!F_ISSET(ply_ptr, PDMINV)) {
  220.                 broadcast_rom(fd, old_rom_ptr->rom_num, "%M went %s.", 
  221.                               ply_ptr, ext_ptr->name);
  222.         }
  223.                                 
  224.  
  225.     del_ply_rom(ply_ptr, ply_ptr->parent_rom);
  226.     add_ply_rom(ply_ptr, rom_ptr);
  227.  
  228.  
  229.     check_traps(ply_ptr, rom_ptr);
  230.     return(0);
  231. }
  232. /**********************************************************************/
  233. /*                          Group_talk                                 */
  234. /**********************************************************************/
  235. /* Group talk allows a player to broadcast a message to everyone in   *
  236.  * their group. gtalk first checks to see if the player is following  *
  237.  * another player; in that case, the group talk message will be sent  *
  238.  * every member in the leader's group.  If the player isn't following *
  239.  * then it is assumed the player is a leader and the message will be    *
  240.  * sent to all the followers in the group. */
  241.  
  242. int gtalk(ply_ptr, cmnd)
  243. creature    *ply_ptr;
  244. cmd     *cmnd;
  245. {
  246.     creature *leader;
  247.     ctag    *cp;
  248.     int     found=0, i, fd;
  249.     int     len;
  250.  
  251.     fd = ply_ptr->fd;
  252.  
  253. if(ply_ptr->following)
  254. {
  255.         leader = ply_ptr->following;
  256.         cp = ply_ptr->following->first_fol;
  257. }
  258.     else
  259. {
  260.         leader = ply_ptr;
  261.         cp = ply_ptr->first_fol;
  262. }
  263.  
  264.     if(!cp) {
  265.         print(fd, "You are not in a group.\n");
  266.         return(0);
  267.     }
  268.     len = strlen(cmnd->fullstr);
  269.     for(i=0; i<  len && i < 256; i++) {
  270.         if(cmnd->fullstr[i] == ' ' && cmnd->fullstr[i+1] != ' ')
  271.             found++;
  272.         if(found==1) break;
  273.     }
  274.     cmnd->fullstr[255] = 0;
  275.  
  276.     if(found < 1 || strlen(&cmnd->fullstr[i+1]) < 1) {
  277.         print(fd, "Group mention what?\n");
  278.         return(0);
  279.     } 
  280.     if(F_ISSET(ply_ptr, PSILNC)) {
  281.         print(fd, "You can't seem to form the words.\n");
  282.         return(0);
  283.     } 
  284.  
  285.     found = 0;          /*if only inv dm in group */
  286.  
  287.     while(cp) {
  288.         if((F_ISSET(cp->crt, PIGNOR) && (ply_ptr->class < CARETAKER)) &&
  289.             !F_ISSET(cp->crt,PDMINV))
  290.             print(fd, "%s is ignoring everyone.\n", cp->crt->name);
  291.         else
  292.             print(cp->crt->fd, "### %M group mentioned, \"%s\".\n", 
  293.                 ply_ptr, &cmnd->fullstr[i+1]);
  294.         if (!F_ISSET(cp->crt,PDMINV))
  295.             found = 1;
  296.         cp = cp->next_tag;
  297.     }
  298.     if(!found)
  299.     {
  300.         print(fd, "You are not in a group.\n");
  301.         return(0);
  302.     }            
  303.         
  304.         if((F_ISSET(leader, PIGNOR) && (ply_ptr->class < CARETAKER)) &&
  305.             !F_ISSET(leader,PDMINV))
  306.             print(fd, "%s is ignoring everyone.\n", leader->name);
  307.         else
  308.             print(leader->fd, "### %M group mentioned, \"%s\".\n",
  309.                 ply_ptr, &cmnd->fullstr[i+1]);     
  310.  
  311.     if (found)
  312.     broadcast_eaves("--- %s group talked: \"%s\".", ply_ptr->name,
  313.              &cmnd->fullstr[i+1]);
  314.  
  315.     return(0);
  316.  
  317. }
  318.  
  319.      
  320. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  321. /*                              lower_prof                              */
  322. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  323. void lower_prof(ply_ptr, exp)
  324. /* The lower_prof function adjusts a player's magical realm and weapon *
  325.  * proficiency after a player loses (exp) amount of experience         */
  326.  
  327. creature   *ply_ptr;
  328. long        exp;
  329. {
  330.     long    profloss, total;
  331.     int     n, below=0;
  332.              
  333.         for(n=0,total=0L; n<5; n++)
  334.             total += ply_ptr->proficiency[n];
  335.         for(n=0; n<4; n++)
  336.             total += ply_ptr->realm[n];
  337.  
  338.         profloss = MIN(exp,total);
  339.         while(profloss > 9L && below < 9) {
  340.             below = 0;
  341.             for(n=0; n<9; n++) {
  342.                 if(n < 5) {
  343.                     ply_ptr->proficiency[n] -=
  344.                        profloss/(9-n);
  345.                     profloss -= profloss/(9-n);
  346.                     if(ply_ptr->proficiency[n] < 0L) {
  347.                         below++;
  348.                         profloss -=
  349.                            ply_ptr->proficiency[n];
  350.                         ply_ptr->proficiency[n] = 0L;
  351.                     }
  352.                 }
  353.                 else {
  354.                     ply_ptr->realm[n-5] -= profloss/(9-n);
  355.                     profloss -= profloss/(9-n);
  356.                     if(ply_ptr->realm[n-5] < 0L) {
  357.                         below++;
  358.                         profloss -=
  359.                             ply_ptr->realm[n-5];
  360.                         ply_ptr->realm[n-5] = 0L;
  361.                     }
  362.                 }
  363.             }
  364.         }
  365.         for(n=1,total=0; n<5; n++)
  366.             if(ply_ptr->proficiency[n] >
  367.                 ply_ptr->proficiency[total]) total = n;
  368.         if(ply_ptr->proficiency[total] < 1024L)
  369.             ply_ptr->proficiency[total] = 1024L;
  370.     return;
  371. }
  372. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  373. /*                              add_prof                                */
  374. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  375. void add_prof(ply_ptr, exp)
  376. /* The add_prof function adjusts a player's magical realm and weapon     *
  377.  * proficiency after the player gains an unassigned amount of experience *
  378.  * such as from a quest item or pkilling.  The exp gain is divided       *
  379.  * between the player's 5 weapon proficiency and 4 magic realms.      */
  380.  
  381. creature   *ply_ptr;
  382. long        exp;
  383. {
  384.     int     n;
  385.           
  386.             if (exp) 
  387.                 exp  = exp/9L;
  388.         else return;
  389.           
  390.             for(n=0; n<9; n++) 
  391.                 if(n < 5)
  392.                     ply_ptr->proficiency[n] += exp;
  393.                 else
  394.                     ply_ptr->realm[n-5]  += exp;
  395.  
  396.         return;
  397. }
  398.  
  399. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  400. /*                              Pledge                                  */
  401. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  402. /* The pledge command allows a player to pledge allegiance to a given  *
  403.  * monster. A pledge players allows the player to use selected items,  *
  404.  * and exits, as well a being able to kill players of the opposing     *
  405.  * kingdoms for experience (regardless if one player is lawful.)  In   *
  406.  * order for a player to pledge, the player needs to be in the correct *
  407.  * room with a correct monster to pledge to. */
  408.  
  409. int pledge(ply_ptr, cmnd)
  410. creature        *ply_ptr;
  411. cmd             *cmnd;
  412. {
  413.         object          *obj_ptr;
  414.         creature        *crt_ptr;
  415.         room            *rom_ptr;
  416.         int             fd, amte, amtg;
  417.  
  418.         fd = ply_ptr->fd;
  419.         rom_ptr = ply_ptr->parent_rom;
  420.     
  421.         amte = REWARD;
  422.         amtg = REWARD *5;
  423.  
  424.         if(cmnd->num < 2) {
  425.                 print(fd, "Join whom's organization?\n");
  426.                 return(0);
  427.         }
  428.  
  429.         if(F_ISSET(ply_ptr,PPLDGK)){
  430.             print(fd, "You have already joined.\n");
  431.             return(0);
  432.         }
  433.  
  434.         if(!F_ISSET(rom_ptr,RPLDGK)){
  435.             print(fd, "You can not join here. \n");
  436.             return(0);
  437.         }
  438.  
  439.         crt_ptr = find_crt(ply_ptr, rom_ptr->first_mon,
  440.                            cmnd->str[1], cmnd->val[1]);
  441.  
  442.         if(!crt_ptr) {
  443.                 print(fd, "I don't see that here.\n");
  444.                 return(0);
  445.         }
  446.  
  447.         if (!F_ISSET(crt_ptr,MPLDGK))
  448.         {
  449.             print(fd, "You can not join %m's organization.\n",crt_ptr);
  450.             return(0);
  451.         }
  452.  
  453.          broadcast_rom(fd, ply_ptr->rom_num, "%M pledges %s allegiance to %m.\n", 
  454.                         ply_ptr,F_ISSET(crt_ptr, PMALES) ? "his":"her", crt_ptr);      
  455.         print(fd, "You kneel before %m as you join the organization.\n",crt_ptr);
  456.   /*      print(fd, "%M draws %s sword and dubs you a member of %s organization.\n", */
  457.   /*      crt_ptr,*/
  458.   /*          F_ISSET(crt_ptr, PMALES) ? "his":"her",*/
  459.    /*         F_ISSET(crt_ptr, PMALES) ? "his":"her");*/
  460.         print(fd,"The room erupts in cheers for the newest member of %m's organization.\n",crt_ptr); 
  461.         print(fd, "You gain %d experience and %d gold!\n",REWARD, REWARD*5); 
  462.  
  463.         ply_ptr->experience += amte;
  464.         add_prof(ply_ptr,amte);
  465.         ply_ptr->gold += amtg;
  466.         ply_ptr->hpcur = ply_ptr->hpmax;
  467.         ply_ptr->mpcur = ply_ptr->mpmax;
  468.  
  469.         F_CLR(ply_ptr, PHIDDN);
  470.         F_SET(ply_ptr,PPLDGK);
  471.         if(F_ISSET(crt_ptr,MKNGDM))
  472.             F_SET(ply_ptr,PKNGDM);
  473.  
  474.     return(0); 
  475.  
  476. }               
  477.  
  478. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  479. /*                              rescind                                 */
  480. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  481. /* The rescind command allows a player to rescind allegiance to a given *
  482.  * monster.  Once a player has rescinded his allegiance, he or she will *
  483.  * lose all the privilliages of rescinded kingdom as well as a          *
  484.  * specified amount of experience and gold. */
  485.  
  486. int rescind(ply_ptr, cmnd)
  487. creature        *ply_ptr;
  488. cmd             *cmnd;
  489. {
  490.         object          *obj_ptr;
  491.         creature        *crt_ptr;
  492.         room            *rom_ptr;
  493.         int             fd, amte, amtg;
  494.  
  495.         fd = ply_ptr->fd;
  496.         rom_ptr = ply_ptr->parent_rom;
  497.         amte = REWARD*10;
  498.         amtg = REWARD*20;
  499.  
  500.         if(cmnd->num < 2) {
  501.                 print(fd, "Rescind to whom?\n");
  502.                 return(0);
  503.         }
  504.  
  505.         if(!F_ISSET(ply_ptr,PPLDGK)){
  506.             print(fd, "You have not joined an organization.\n");
  507.             return(0);
  508.         }
  509.  
  510.         if(!F_ISSET(rom_ptr,RRSCND)){
  511.             print(fd, "You can not rescind your allegiance here.\n");
  512.             return(0);
  513.         }
  514.  
  515.         crt_ptr = find_crt(ply_ptr, rom_ptr->first_mon,
  516.                            cmnd->str[1], cmnd->val[1]);
  517.  
  518.         if(!crt_ptr) {
  519.                 print(fd, "I don't see that here.\n");
  520.                 return(0);
  521.         }
  522.  
  523.         if(BOOL(F_ISSET(crt_ptr,MKNGDM)) != BOOL(F_ISSET(ply_ptr,PKNGDM))){
  524.             print(fd, "You are in the wrong organization to rescind!\n");
  525.             return(0);
  526.         }
  527.  
  528.         if (ply_ptr->gold < amtg){
  529.             print(fd, "You do not have sufficient gold to rescind.\n");
  530.             return (0);
  531.         }
  532.  
  533.         if (!F_ISSET(crt_ptr,MRSCND))
  534.         {
  535.             print(fd, "You can not rescind your allegiance to %m.\n",crt_ptr);
  536.             return(0);
  537.         }
  538.  
  539.          broadcast_rom(fd, ply_ptr->rom_num, "%M rescinds %s allegiance to %m.\n", 
  540.                   ply_ptr,F_ISSET(crt_ptr, PMALES) ? "his":"her", crt_ptr);      
  541.         print(fd, "%M scourns you as you are stripped of all your rights and privileges!\n", crt_ptr);
  542.         print(fd, "\nThe room fills with boos and hisses as you are ostracized from %m's organization.\n", 
  543.             crt_ptr); 
  544.  
  545.         amte = MIN(amte,ply_ptr->experience);
  546.         print(fd, "\nYou lose %d experience and %d gold!\n",amte,amtg); 
  547.         lower_prof(ply_ptr,amte);
  548.         ply_ptr->experience -= amte;
  549.         ply_ptr->gold -= amtg;
  550.         ply_ptr->hpcur = ply_ptr->hpmax/3;
  551.         ply_ptr->mpcur = 0;
  552.  
  553.         F_CLR(ply_ptr, PHIDDN);
  554.         F_CLR(ply_ptr,PPLDGK);
  555.         F_CLR(ply_ptr,PKNGDM);
  556.  
  557.  
  558.     return(0); 
  559.  
  560. }               
  561. /*====================================================================*/
  562. /*                              lose_all                             */
  563. /*====================================================================*/
  564. /* lose_all causes the given player to lose all his or her possessions *
  565.  * including any equipted items.                                       */
  566.  
  567. void lose_all(ply_ptr)
  568. creature    *ply_ptr;
  569. {
  570.     object  *obj_ptr;
  571.     room    *rom_ptr;
  572.     otag    *op;
  573.     int fd, i;
  574.  
  575.     fd = ply_ptr->fd;
  576.     rom_ptr = ply_ptr->parent_rom;
  577.  
  578. /* remove all equipted items */
  579.     for(i=0; i<MAXWEAR; i++) {
  580.         if(ply_ptr->ready[i] && !F_ISSET(ply_ptr->ready[i], OCURSE)) {
  581.             F_CLR(ply_ptr->ready[i], OWEARS);
  582.             add_obj_crt(ply_ptr->ready[i], ply_ptr);
  583.             ply_ptr->ready[i] = 0;
  584.         }
  585.     }
  586.  
  587.  
  588.     compute_ac(ply_ptr);
  589.     compute_thaco(ply_ptr);
  590.  
  591. /* remove and delete all possessions */
  592.     op = ply_ptr->first_obj;
  593.     while(op) {
  594.             obj_ptr = op->obj;
  595.             op = op->next_tag;
  596.             del_obj_crt(obj_ptr, ply_ptr);
  597.             free_obj(obj_ptr);
  598.     }
  599.  
  600. }
  601.  
  602. /**********************************************************************/
  603. /*                      dissolve_item                                 */
  604. /**********************************************************************/
  605. /* dissolve_item will randomly select one equipted (including held or *
  606.  * wield) items on the given player and then delete it. The player    *
  607.  * receives a message that the item was destroyed as well as who is   *
  608.  * responsible for the deed.                                          */
  609. void dissolve_item (ply_ptr,crt_ptr)
  610. creature    *ply_ptr;
  611. creature    *crt_ptr;
  612. {
  613.     int     n;
  614.     char    checklist[MAXWEAR];
  615.     int     numwear=0, i;
  616.  
  617.         for(i=0; i<MAXWEAR; i++) {
  618.                 checklist[i] = 0;
  619. /*                if(i==WIELD-1 || i==HELD-1) continue; */
  620.                 if(ply_ptr->ready[i])
  621.                         checklist[numwear++] = i+1;
  622.         }
  623.  
  624.         if(!numwear) 
  625.             n = 0;
  626.         else {
  627.             i = mrand(0, numwear-1);
  628.             n = (int) checklist[i];
  629.         }
  630.             
  631.         if(n) {
  632.             broadcast_rom(ply_ptr->fd,ply_ptr->rom_num,"%M destroys %m's %s.",
  633.                 crt_ptr, ply_ptr, ply_ptr->ready[n-1]->name);
  634.         print(ply_ptr->fd,"%M destroys your %s.\n",crt_ptr,
  635.         ply_ptr->ready[n-1]->name); 
  636.             free_obj(ply_ptr->ready[n-1]);
  637.             ply_ptr->ready[n-1] = 0;
  638.             compute_ac(ply_ptr);
  639.                     }
  640.     return;
  641. }            
  642.  
  643. /**********************************************************************/
  644. /*                              purchase                              */
  645. /**********************************************************************/
  646. /* purchase allows a playe rto buy an item from a monster.  The      *
  647.  * purchase item flag must be set, and the monster must have an    *
  648.  * object to sell.  The object for sale is determined by the first   *
  649.  * object listed in carried items. */
  650.  
  651. int purchase(ply_ptr, cmnd)
  652. creature        *ply_ptr;
  653. cmd             *cmnd;
  654. {
  655.         creature        *crt_ptr;
  656.         room            *rom_ptr;
  657.         object        *obj_ptr, *obj_list[10];
  658.         int            maxitem = 0,obj_num[10];
  659.         long        amt;
  660.         int         fd, i, j, found = 0, match = 0;
  661.  
  662.         fd = ply_ptr->fd;
  663.         rom_ptr = ply_ptr->parent_rom;
  664.  
  665.         if(cmnd->num < 2) {
  666.                 print(fd, "Purchase what?\n");
  667.                 return(0);
  668.         }
  669.  
  670.         if(cmnd->num < 3 ) {
  671.                 print(fd, "Syntax: purchase <item> <monster>\n");
  672.                 return(0);
  673.         }
  674.  
  675.         crt_ptr = find_crt(ply_ptr, rom_ptr->first_mon, cmnd->str[2],
  676.                            cmnd->val[2]);
  677.  
  678.         if(!crt_ptr) {
  679.                 print(fd, "That is not here.\n");
  680.                 return(0);
  681.         }
  682.     
  683.     if (!F_ISSET(crt_ptr,MPURIT)){
  684.         print(fd, "You can not purchase objects from %m.\n",crt_ptr);
  685.         return(0);
  686.     }
  687.  
  688.     for (i=0;i <  10; i++)
  689.         if (crt_ptr->carry[i] > 0){
  690.             found = 0;
  691.             for(j=0; j< maxitem; j++)
  692.             if (crt_ptr->carry[i] == obj_num[j])
  693.                 found = 1;
  694.             if (!found){
  695.             maxitem++;
  696.             obj_num[i] = crt_ptr->carry[i];
  697.             }
  698.         }
  699.  
  700.     if (!maxitem){
  701.         print(fd, "%M has nothing to sell.\n",crt_ptr);
  702.         return(0);
  703.     }
  704.     
  705.     found = 0;
  706.     for(i=0;i< maxitem; i++){
  707.         if (!(load_obj(crt_ptr->carry[i], &obj_ptr) < 0))
  708.         if(EQUAL(obj_ptr, cmnd->str[1]) && (F_ISSET(ply_ptr, PDINVI) ?
  709.                    1:!F_ISSET(obj_ptr, OINVIS))) { 
  710.                         match++;
  711.                         if(match == cmnd->val[1]) {
  712.                                 found = 1;
  713.                                 break;
  714.                         }
  715.                 }
  716.     }
  717.  
  718.     if(!found){
  719.         print(fd, "%M says, \"Sorry, I don't have any of those to sell.\"\n", crt_ptr);
  720.         return(0);
  721.     }
  722.  
  723.  
  724.     amt =  MAX(10,obj_ptr->value*1);
  725.         if(ply_ptr->gold < amt){
  726.                 print(fd, 
  727.         "%M says \"The price is $%d, and not a gold piece less!\"\n",crt_ptr,amt);
  728.         }
  729.         else {
  730.         print(fd, "You pay %m %d gold pieces.\n",crt_ptr,amt);
  731.                 print(fd, "%M says, \"Thank you very much.  Here is your %s.\"\n",crt_ptr,obj_ptr->name);
  732.             broadcast_rom(fd, ply_ptr->rom_num, "%M pays %m $%d for %i.\n", ply_ptr, crt_ptr, amt, obj_ptr);          
  733.                 ply_ptr->gold -= amt;
  734.         add_obj_crt(obj_ptr, ply_ptr);      
  735.         }
  736.  
  737.         return(0);
  738.  
  739. }                 
  740.  
  741.  
  742. /**********************************************************************/
  743. /*                              selection                              */
  744. /**********************************************************************/
  745. /* The selection command  lists all the items  a monster is selling.  *
  746.  * The monster needs the MPURIT flag set to denote it can sell. */
  747.  
  748. int selection(ply_ptr, cmnd)
  749. creature        *ply_ptr;
  750. cmd             *cmnd;
  751. {
  752.         creature        *crt_ptr;
  753.         room            *rom_ptr;
  754.     object        *obj_ptr[10];
  755.     int        obj_list[10];
  756.     int         fd, i, j, found = 0, maxitem = 0;
  757.  
  758.         fd = ply_ptr->fd;
  759.         rom_ptr = ply_ptr->parent_rom;
  760.  
  761.         if(cmnd->num < 2) {
  762.                 print(fd, "Ask who for a selection?\n");
  763.                 return(0);
  764.         }
  765.  
  766.  
  767.         crt_ptr = find_crt(ply_ptr, rom_ptr->first_mon, cmnd->str[1],
  768.                            cmnd->val[1]);
  769.  
  770.         if(!crt_ptr) {
  771.                 print(fd, "That is not here.\n");
  772.                 return(0);
  773.         }
  774.  
  775.     if(!F_ISSET(crt_ptr,MPURIT)){
  776.         print(fd, "%M is not selling anything.\n",crt_ptr);
  777.         return(0);
  778.     }
  779.     
  780.     for (i=0;i <  10; i++)
  781.         if (crt_ptr->carry[i] > 0){
  782.             found = 0;
  783.             for(j=0; j< maxitem; j++)
  784.             if (crt_ptr->carry[i] == obj_list[j])
  785.                 found = 1;
  786.             
  787.             if (!found){
  788.             maxitem++;
  789.             obj_list[i] = crt_ptr->carry[i];
  790.             }
  791.         }
  792.  
  793.     if(!maxitem){
  794.         print(fd, "%M has nothing to sell.\n",crt_ptr);
  795.         return(0);
  796.     }
  797.     print(fd, "%M is currently selling:\n",crt_ptr);
  798.     for (i=0;i<maxitem;i++)
  799.         if ((load_obj(crt_ptr->carry[i], &(obj_ptr[i])) < 0)  ||
  800.             (crt_ptr->carry[i] == 0))
  801.             print(fd,"%d) Out of stock.\n",i+1);
  802.         else 
  803.             print(fd,"%d) %-22s    %ldgp\n",i+1, 
  804.                 (obj_ptr[i])->name,MAX(10,((obj_ptr[i])->value)));
  805.     print(fd,"\n"); 
  806.         return(0);
  807.  
  808. }                 
  809.  
  810.  
  811.  
  812. /**********************************************************************/
  813. /*            trade                          */
  814. /**********************************************************************/
  815. int trade(ply_ptr, cmnd)
  816. creature        *ply_ptr;
  817. cmd             *cmnd;
  818. {
  819.         creature    *crt_ptr;
  820.         room        *rom_ptr;
  821.     object        *obj_ptr, *trd_ptr;
  822.         int         obj_list[5][2];
  823.         int         fd, i, j, found = 0, maxitem = 0;
  824.  
  825.         fd = ply_ptr->fd;
  826.         rom_ptr = ply_ptr->parent_rom;
  827.  
  828.         if(cmnd->num < 2) {
  829.                 print(fd, "Trade what?\n");
  830.                 return(0);
  831.         }
  832.  
  833.         if(cmnd->num < 3) {
  834.                 print(fd, "Syntax: trade <item> <monster>\n");
  835.                 return(0);
  836.         }
  837.  
  838.         crt_ptr = find_crt(ply_ptr, rom_ptr->first_mon, cmnd->str[2],
  839.                            cmnd->val[2]);
  840.  
  841.         if(!crt_ptr) {
  842.                 print(fd, "That is not here.\n");
  843.                 return(0);
  844.         }
  845.  
  846.         if(!F_ISSET(crt_ptr,MTRADE)){
  847.                 print(fd, "You can't trade with %m.\n",crt_ptr);
  848.                 return(0);
  849.         }
  850.  
  851.         obj_ptr = find_obj(ply_ptr, ply_ptr->first_obj,
  852.                            cmnd->str[1], cmnd->val[1]);
  853.  
  854.         if(!obj_ptr) {
  855.                 print(fd, "You don't have that.\n");
  856.                 return(0);
  857.         }
  858.                 
  859.         
  860.         for (i=0;i <  5; i++)
  861.                 if (crt_ptr->carry[i] > 0){
  862.                     found = 0;
  863.                     for(j=0; j< maxitem; j++)
  864.                         if (crt_ptr->carry[i] == obj_list[j][0])
  865.                                 found = 1;
  866.                     
  867.                     if (!found){
  868.                         maxitem++;
  869.                         obj_list[i][0] = crt_ptr->carry[i];
  870.                         obj_list[i][1] = crt_ptr->carry[i+5];
  871.                     }
  872.                 }
  873.  
  874.         if(!maxitem){
  875.                 print(fd, "%M has nothing to trade.\n",crt_ptr);
  876.                 return(0);
  877.         }
  878.  
  879.     found = 0;
  880.     for(i=0;i < maxitem; i++){
  881.     if (load_obj(obj_list[i][0], &trd_ptr) < 0)
  882.         continue;
  883.         if (!strcmp(obj_ptr->name, trd_ptr->name)){
  884.             found = i+1;
  885.             break;
  886.         }
  887.     } 
  888.  
  889.     if(!found || ((obj_ptr->shotscur <= obj_ptr->shotsmax/10)&&(obj_ptr->type != MISC)))
  890.         print(fd,"%M says, \"I don't want that!\"\n",crt_ptr);
  891.     else{
  892.         if (crt_ptr->carry[found+4] == 0){
  893.                 del_obj_crt(obj_ptr, ply_ptr);
  894.                 add_obj_crt(obj_ptr, crt_ptr); 
  895.             print(fd, "%M says, \"Thanks!, I really needed %i.\n",
  896.                  crt_ptr,obj_ptr);
  897.              print(fd, "Sorry I don't have anything for you.\"\n");
  898.             broadcast_rom(fd, ply_ptr->rom_num,"%M gives %m %i.\n",
  899.                 ply_ptr,crt_ptr,obj_ptr);
  900.         }
  901.         else if(!(load_obj((obj_list[found-1][1]), &trd_ptr) < 0)){ 
  902.  
  903.               if(trd_ptr->questnum && Q_ISSET(ply_ptr, trd_ptr->questnum-1)) {
  904.                         print(fd, "You have already fulfilled that quest.\n");
  905.                         return(0);
  906.                 }                    
  907.                 del_obj_crt(obj_ptr, ply_ptr);
  908.                 add_obj_crt(obj_ptr, crt_ptr); 
  909.                 add_obj_crt(trd_ptr, ply_ptr); 
  910.  
  911.             print(fd,"%M says, \"Thank you for retrieving %i for me.\n",
  912.                 crt_ptr,obj_ptr);
  913.             print(fd,"For your deed I will give you %i.\"\n",trd_ptr);
  914.             print(fd,"%M gives you %i.\n",crt_ptr,trd_ptr);
  915.             broadcast_rom(fd, ply_ptr->rom_num,"%M gives %m %i.\n",
  916.                 ply_ptr,crt_ptr,obj_ptr);
  917.     /*        broadcast_rom(fd, ply_ptr->rom_num,"%M gives %m %i.\n", */
  918.     /*            ply_ptr,crt_ptr,obj_ptr); */
  919.  
  920. /* if return object is a quest item */
  921.               if(trd_ptr->questnum) {
  922.                             print(fd, "Quest fulfilled!  Don't drop it.\n");
  923.                             print(fd, "You won't be able to pick it up again.\n");  
  924.                          Q_SET(ply_ptr, trd_ptr->questnum-1);
  925.                          ply_ptr->experience += quest_exp[trd_ptr->questnum-1];
  926.                          print(fd, "%ld experience granted.\n",
  927.                                 quest_exp[trd_ptr->questnum-1]);
  928.                          add_prof(ply_ptr,quest_exp[trd_ptr->questnum-1]);
  929.                 }     
  930.        }
  931.  
  932.     }
  933.     return(0);    
  934. }             
  935.  
  936. int room_obj_count(first_obj)
  937. otag     *first_obj;
  938. {
  939.  
  940.     long num = 0;
  941.  
  942.     while (first_obj)
  943. {
  944.         num++;
  945.         first_obj = first_obj->next_tag;
  946. }
  947.     return (num);
  948. }
  949.